package com.tools.ad.adscene.outer;

import com.hm.ads.sdk.HmAdsSDK;
import com.hm.adsbuisiness.bean.HmAdUnionPlace;
import com.hm.adsbuisiness.bean.interstitial.AMNRawInterstitialAd;
import com.hm.adsbuisiness.bean.interstitial.AMRawInterstitialAd;
import com.hm.adsbuisiness.bean.interstitial.MpRawInterstitialAd;
import com.hm.adsbuisiness.service.AdActionException;
import com.hm.adsui.card.CommonNativeAdCardView;
import com.hm.base.android.mob.AMApplication;
import com.tools.ad.AdType;
import com.tools.ad.EntranceType;
import com.tools.ad.adscene.AdStrategyScene;
import com.tools.ad.manager.InnerHookManager;
import com.tools.ad.strategy.IStrategyExecutor;

/**
 * desc: 在DAP天气详情页中，HOOK点击，新增一个全屏广告
 * date: 2018/4/20
 * author: ancun
 */

public class WeatherFullScreenScene extends AdStrategyScene {

    private IStrategyExecutor mExecutor;

    public WeatherFullScreenScene(AMApplication context, EntranceType entranceType) {
        super(context, entranceType);
    }

    @Override
    public boolean load(boolean forceLoad) {
        HmAdUnionPlace adUnionPlace = HmAdsSDK.getInstance().getUnionAd(mEntranceType.getPid());
        if (adUnionPlace == null) {
            InnerHookManager.showWeatherUrl(imContext);
            return false;
        }

        mExecutor = getADModule().getADStrategyManager().getExecutorByEntranceType(mEntranceType);
        if (forceLoad || mExecutor.check(adUnionPlace)) {
            return loadUnionPlace(adUnionPlace);
        } else {
            InnerHookManager.showWeatherUrl(imContext);
            return false;
        }

    }

    @Override
    protected CommonNativeAdCardView initCardView() {
        return null;
    }

    @Override
    protected void onADLoaded(AdType adType) {
        switch (adType) {
            case AM_INTERSTITIAL:
                if (activeAd instanceof AMRawInterstitialAd) {
                    try {
                        ((AMRawInterstitialAd) activeAd).show();
                    } catch (AdActionException e) {
                        e.printStackTrace();
                    }
                }
                break;
            case AM_NEW_INTERSTITIAL:
                if (activeAd instanceof AMNRawInterstitialAd) {
                    try {
                        ((AMNRawInterstitialAd) activeAd).show();
                    } catch (AdActionException e) {
                        e.printStackTrace();
                    }
                }
                break;
            case MP_INTERSTITIAL:
                if (activeAd instanceof MpRawInterstitialAd) {
                    try {
                        ((MpRawInterstitialAd) activeAd).show();
                    } catch (AdActionException e) {
                        e.printStackTrace();
                    }
                }
                break;
        }
    }

    @Override
    protected void onADClick(AdType adType) {

    }

    @Override
    protected void onADShow(AdType adType) {
        switch (adType) {
            case AM_INTERSTITIAL:
            case AM_NEW_INTERSTITIAL:
                mExecutor.record();
                break;
        }
    }


    @Override
    protected void onAdClose(AdType adType) {
        switch (adType) {
            case AM_INTERSTITIAL:
            case AM_NEW_INTERSTITIAL:
                InnerHookManager.showWeatherUrl(imContext);
                break;
        }
    }

    @Override
    protected void onADLoad(AdType adType) {

    }

    @Override
    protected void onADFail(AdType adType, int code) {

    }

    @Override
    protected void onADFilled(AdType adType) {

    }
}
